package com.zxy.activemqjms;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;
import java.io.IOException;

/**
 * @author zhangxuyuan
 * @version 1.0
 * @date 2020/11/22
 */
public class PTP_Consumer {

    //简化版看测试文件夹

    public static void main(String[] args) throws JMSException, IOException {
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");

        Connection connection = connectionFactory.createConnection();

        connection.start();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        Queue queue1 = session.createQueue("queue1");

        MessageConsumer consumer = session.createConsumer(queue1);

        consumer.setMessageListener(new MessageListener() {
            public void onMessage(Message message) {
                if(message != null && message instanceof TextMessage)
                {
                    TextMessage textMessage = (TextMessage)message;

                    try {
                        System.out.println(textMessage.getText());
                    } catch (JMSException e) {
                        e.printStackTrace();
                    }
                }
            }
        });

        System.in.read();
    }
}
